package twinb.text;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Regex {
	
	static String URL = "(((ht|f)tp(s?))://)?(www\\.|[a-zA-Z]+\\.)[a-zA-Z0-9\\p{Punct}]+";
	static String WORD="([\\W&&[^\\p{Punct}\\s~！￥%……&*（）——+{}|”：？》《=【】、’；、。，]])|([a-zA-Z_0-9]+)";
	static String TAG="([@|#][\\W&&[^\\p{Punct}\\s~！￥%……&*（）——+{}|”：？》《=【】、’；、。，]])|([@|#][a-zA-Z_0-9]+)";
	static Pattern patURL = Pattern.compile(URL);
	static Pattern patWORD = Pattern.compile(WORD);
	static Pattern patTAG = Pattern.compile(TAG);
    static Matcher m ;
	
	public List<String> getWords(String text)
	{
		text=text.toLowerCase();
		List<String> ans=new ArrayList<String>();
        m = patURL.matcher(text);
        String textWords=m.replaceAll(" ");
        m = patWORD.matcher(textWords);
        while(m.find())
        	ans.add(m.group());
        m = patTAG.matcher(textWords);
        while(m.find())
        	ans.add(m.group());
        
        return ans;
	}
	
	public List<String> getUrls(String text)
	{
		List<String> ans=new ArrayList<String>();
        m = patURL.matcher(text);
        while(m.find())
        	ans.add(m.group());
        return ans;
	}

}
